$(document).ready(function () {

	$('#set_form').validate({
		
		submitHandler: function() {
		
			$('#set_form').ajaxSubmit({
				beforeSubmit: function() {
					// loading image
					$('#set_send').attr('disabled', true);
					$('#set_message').html('<div><img src="../../images/icons/ajax-loader.gif" alt="Chargement ..." /></div>');
					$('#set_message').show();
				},
				dataType: 'json',
				success: function(e) {
				
					if(e.result) {
						$('#set_form').fadeOut();
						$('#set_message').html('<div class="success">'+e.message+'</div>');
						$('#set_message').fadeIn();
						setTimeout("$('#set_message').html('<div class=\"success\">Redirection ...</div>')", 2000);
						setTimeout("window.location.href = '"+$('#redirection').val()+"'", 2000);
					
					} else {
					
						$('#set_message').html('<div class="error">'+e.message+'</div>');
						$('#set_message').show();
						$('#set_send').removeAttr('disabled');
						setTimeout("$('#set_message').fadeOut()", 2000);
				
					}
				},
				error: function(e) {
					alert(e);
					$('#set_send').removeAttr('disabled');
				}
			
			});
		
		}
	
	});

});
